package org.taurusxi.apiprovider.mvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.taurusxi.cloudbean.ApiModel;

/**
 * Created by chengxi on 2017/8/27.
 */

@RestController
@RequestMapping(path = "/index",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RefreshScope
public class IndexJavaController {


    @Autowired
    private DiscoveryClient client;

    @Autowired
    private Registration registration;


    @Value("${testconfig.id}")
    private String id;


    @Value("${testconfig.name}")
    private String name;


    @RequestMapping(path= "/hello", method = RequestMethod.GET)
    ApiModel sayHello(){

        ServiceInstance instance = client.getLocalServiceInstance();

        String serviceId = registration.getServiceId();
        String msg = "Index，say hello__host:" + instance.getHost() +"__port:"+instance.getPort()+ "__serverId:" + instance.getServiceId() + "__registrationId:" + serviceId +"__id:"+ id +"___name:"+name;
        return new ApiModel(1000, msg);
    }

}
